package scalab.core.event

import scalab.core.component.{ExecutableComponent, Target}

sealed trait Event{
	//val target: Buildable
}

sealed trait UpdateEvent extends Event{
	val target: Buildable
}

sealed trait UpdateStarted extends UpdateEvent
object UpdateStarted{
	private[core] def apply(t: Buildable): UpdateStarted = new UpdateStarted{
		val target = t 
	}
}

sealed trait UpdateFinished extends UpdateEvent{
	val succeded: Boolean
}
object UpdateFinished{
	def apply(t: Buildable, res: Boolean): UpdateFinished = new UpdateFinished{
		val target = t 
		val succeded = res
	}
}

sealed trait CacheEvent extends Event{
	val target: ExecutableComponent
}

sealed trait RunEvent extends CacheEvent

sealed trait RunStarted extends RunEvent
object RunStarted{
	def apply(t: ExecutableComponent): RunStarted = new RunStarted{
		val target = t
	}
}

sealed trait RunFinished extends RunEvent{
	val succeeded: Boolean
}
object RunFinished{
	def apply(t: ExecutableComponent, res: Boolean): RunFinished = new RunFinished{
		val target = t
		val succeeded = res
	}
}

sealed trait LoadEvent extends CacheEvent

sealed trait LoadStarted extends LoadEvent
object LoadStarted{
	def apply(t: ExecutableComponent): LoadStarted = new LoadStarted{
		val target = t
	} 
}

sealed trait LoadFinished extends LoadEvent{
	val willExecute: Boolean
}
object LoadFinished{
	def apply(t: ExecutableComponent, ex: Boolean): LoadFinished = new LoadFinished{
		val target = t
		val willExecute = ex
	}
}

sealed trait StoreEvent extends CacheEvent

sealed trait StoreStarted extends StoreEvent
object StoreStarted{
	def apply(t: ExecutableComponent): StoreStarted = new StoreStarted{
		val target = t
	}
}

sealed trait StoreFinished extends StoreEvent{
	val succeeded: Boolean
}
object StoreFinished{
	def apply(t: ExecutableComponent, res: Boolean): StoreFinished = new StoreFinished{
		val target = t
		val succeeded = res
	}
}

sealed trait ExecutionEvent extends Event{
	val target: ExecutableComponent
}

sealed trait ExecutionStarted extends ExecutionEvent
object ExecutionStarted{
	def apply(t: ExecutableComponent): ExecutionStarted = new ExecutionStarted{
		val target = t 
	}
}

sealed trait ExecutionFinished extends ExecutionEvent{
	val succeeded: Boolean
}
object ExecutionFinished{
	def apply(t: ExecutableComponent, res: Boolean): ExecutionFinished = new ExecutionFinished{
		val target = t
		val succeeded = res
	}
}

sealed trait BuildEvent extends Event{
	val target: Target
}

sealed trait BuildStarted extends BuildEvent
object BuildStarted{
	private[core] def apply(t: Target): BuildStarted = new BuildStarted{
		val target = t
	}
}

sealed trait BuildFinished extends BuildEvent{
	val succeeded: Boolean
}
object BuildFinished{
	def apply(t: Target, res: Boolean): BuildFinished = new BuildFinished{
		val target = t
		val succeeded = res
	}
}
